<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_base.css">
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_tooltip.css">
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_lib.css" />
<style>
.table tr td{text-align:center;vertical-align:middle;}
.table tr td:first-child{width:50%;}
.table tr td:last-child{width:20%;}
ul.mater{border:1px solid #e7e7eb;border-radius:5px;}
ul.mater li{padding:5px;border-bottom:1px solid #e7e7eb;}
ul.mater li:first-child{padding:13px 5px;}
ul.mater li:last-child{border-bottom:0px solid #e7e7eb;}
ul.mater li .btn_primary{display:inline-block;padding:3px;border-radius:3px;margin-right:10px;}
.dialog_ft .page{background:#f4f5f9;margin-top:10px;}
.btn:hover, .btn:focus{background-position: 0 0;}
.btn:focus{color:#ffffff;}
.btn{text-shadow: 0 0 0;}
.icon14_common {height: 17px}
.btn_primary:hover{
	background:#126AE4;
}
.dialog_hd h3{font-size:20px;line-height:52px;}
</style>
<div class="dialog_wrp media align_edge ui-draggable" style="display:none;width: 960px; margin-left: -480px; margin-top: -313.5px;" id="dialog_media">
	<div class="dialog">
		<div class="dialog_hd">
			<h3>选择素材</h3>
			<a href="javascript:;" onclick="closeMaterial()" class="icon16_opr closed pop_closed">关闭</a>
		</div>
		<div class="dialog_bd">
			<div class="dialog_media_container appmsg_media_dialog">
				<div class="sub_title_bar in_dialog">
					<div class="search_bar js-btn-media">
						<button class="btn-common-white btn-big btn_primary" value="1" href="javascript:;" onclick="checkBtn(this)"> 文本 </button>
						<button class="btn-common-white btn-big" value="2" href="javascript:;" onclick="checkBtn(this)"> 单图文 </button>
						<button class="btn-common-white btn-big" href="javascript:;" value="3" onclick="checkBtn(this)"> 多图文 </button>
					</div>
					<div class="appmsg_create tr" id="add_message_btn">
						<a target="_blank" href="{:__URL('ADMIN_MAIN/wchat/addmedia?type=1')}"><button class="btn-common"><i class="icon14_common add_white"></i><span>新建文本消息</span></button></a>
					</div>
				</div>
				<div class="dialog_media_inner" style="overflow:auto;">
					<div class="table_wrp user_list">
						<table class="table" cellspacing="0">
							<tbody class="tbody" id="materia_data"></tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
		<div class="dialog_ft">
			{include file="adminblue/pageCommon" /}
		</div>
	</div>
</div>
<div class="mask mask_metar" style="display: none;"></div>
<script>
function checkBtn(event){
	$(".js-btn-media").find('.btn-common-white').removeClass('btn_primary');
	$(event).addClass('btn_primary');
	var type = $(event).attr('value');
	var type_name = '';
	if(type == 1){
		type_name = '文本';
	}else if(type == 2){
		type_name = '单图文';
	}else if(type == 3){
		type_name = '多图文';
	}
	$('#add_message_btn').find('a').attr('href',__URL('ADMIN_MAIN/wchat/addmedia?type=' + type))
	$('#add_message_btn').find('span').html('新建'+ type_name +'消息');
	LoadingInfo(1);
}

//显示素材
function showMaterial(){
	$("#dialog_media").fadeIn(500);
	$(".mask_metar").fadeIn(300);
}

//加载 素材 数据
function LoadingInfo(page_index){
	var type = $(".js-btn-media .btn_primary").attr('value');
	var search_text = '';
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/wchat/onloadmaterial')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val(),
			"search_text" : search_text, 
			"type" : type
		},
		success : function(data) {
			if(data['data'].length > 0){
				$("#materia_data").empty();
				for(var i=0; i<data['data'].length; i++){
					var html = '';
					if(data['data'][i]['type'] == 1){
						var type_name = '文本 ';
					}else if(data['data'][i]['type'] == 2){
						var type_name = '单图文 ';
					}else if(data['data'][i]['type'] == 3){
						var type_name = '多图文 ';
					}
					html += '<tr><td class="table_cell"><ul class="mater">';
					for(var l=0; l<data['data'][i]['item_list'].length; l++){
						var k = l+1;
						html += '<li><span class="btn_primary">'+ type_name + k+' </span><a href="#">'+data['data'][i]['item_list'][l]['title']+'</a></li>';
					}
					html += '</ul></td>';
					html += '<td>'+timeStampTurnTime(data['data'][i]['create_time'])+'</td>';
					html += '<td class="table_cell user_opr tr"><a class="btn remark js_msgSenderRemark" onclick="selectedMaterial('+data['data'][i]['media_id']+')">选取</a></td>';
					html += '</tr>';
					$("#materia_data").append(html);
				}
			}else{
				html += '<tr>';
				html += '<td colspan="3" class="table_cell" style="text-align:center;">暂无素材</td>';
				html += '</tr>';
				$("#materia_data").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

//选择 图文素材
function selectedMaterial(media_id){
	getMaterial(media_id);
	closeMaterial();
}

//取消  关闭
function closeMaterial(){
	$("#dialog_media").fadeOut(300);
	$(".mask_metar").fadeOut();
}
</script>